package com.yunhe.tianhe.rentcars.controller.system;

import com.yunhe.tianhe.rentcars.dto.JSONResponse;
import com.yunhe.tianhe.rentcars.dto.TreeNode;
import com.yunhe.tianhe.rentcars.entity.system.SysDict;
import com.yunhe.tianhe.rentcars.service.system.SysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * # @Author: 贾波
 * # @Time: 2017-11-25-上午 11:24
 * # Description:
 */
@Controller
@RequestMapping("/sysDict")
public class SysDictController {
    @Autowired
    private SysDictService sysDictService;
    @RequestMapping
    public String add(){
        return "/system/sysDict/add";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JSONResponse save(SysDict sysDict){
        Long code = sysDictService.save(sysDict);
        return JSONResponse.success("保存成功",code);
    }


    @RequestMapping("/update")
    @ResponseBody
    public JSONResponse update(SysDict sysDict){
        Long code = sysDictService.update(sysDict);
        return JSONResponse.success("修改成功",code);
    }

    @RequestMapping("/tree")
    @ResponseBody
    public JSONResponse tree(SysDict sysDict){
        List<TreeNode> treeNodes = sysDictService.findTreeNodes(sysDict);
        return JSONResponse.success("树节点加载成功",treeNodes);
    }

    @RequestMapping("/parent")
    @ResponseBody
    public JSONResponse parent(String name,String parentname){
        SysDict sysDict = sysDictService.findOne(name);
        return JSONResponse.success("",sysDict);
    }

}
